import { Injectable } from '@angular/core'
import { HttpClientService } from 'src/app/common/httpClient/http'
import { CommonUtil } from 'src/app/common/utils/common.util'
import { CoolLocalStorage } from 'src/app/common/coolStorage/cool-local-storage'

@Injectable({
  providedIn: 'root'
})
export class HomeService {
  start = ''
  end = ''
  reqdata = {
    pager: { Start: 10, Limit: 10 },
    filter: {
      Lambda: '',
      Latitude: null,
      Longitude: null,
      Navigations: []
    },
    sorters: [{ Property: 'item=>item.Sort', Direction: 'Descending' }]
  }

  constructor(private http: HttpClientService, private utils: CommonUtil, private storage: CoolLocalStorage) {
    let location: any = storage.getObject('location')
    this.start = this.utils.time2UTC(new Date())
    this.end = this.utils.time2UTC(new Date())
    if (location) {
      this.reqdata.filter.Latitude = location.latitude
      this.reqdata.filter.Longitude = location.longitude
    }
  }

  getEstateList(callback, errorBack?) {
    let zone = this.storage.getItem('zone')
    let lambda = `item=>item.Publish&&!item.Enable&&item.Start<=${this.start}&&item.end>=${
      this.end
    }&&item.Zone==${zone}`
    this.reqdata.filter.Lambda = lambda
    this.http.post(this.reqdata, '/House1/Json/CooperationService.svc/QueryProjectSummary', callback, errorBack)
  }
}
